const responseData = require('../responseData')
const roleData = require('./roles')
module.exports = [
	{
		url: 'apimember/lists',
		type: 'post',
		response: config => {
			const body = config.body
			const limit = body.limit || 10
			const pageTotal = parseInt(Math.random() * 10) || 1
			let dataOptions = {
				page_index: body.p,
				page_limit: limit,
				page_total: pageTotal,
				row_total: pageTotal * limit
			}
			dataOptions['items|' + limit] = [
				{
					'id|+1': 1 + (body.p - 1) * limit,
					created: Math.ceil(Date.now() / 1000),
					updated: Math.ceil(Date.now() / 1000),
					status: () => ('status' in body ? body.status : Math.random() > 0.5 ? 0 : 1),
					name: '@cname',
					phone: /1(3|5|7|8|9)[0-9][0-9]{8}/,
					wx: '@string',
					passWord: '@string'
				}
			]
			return responseData(dataOptions)
		}
	},
	{
		url: 'apimember/delMember',
		type: 'post',
		response: config => {
			const body = config.body
			return responseData()
		}
	},
	{
		url: 'apimember/memberDetail',
		type: 'post',
		response: config => {
			return responseData(
				Object.assign(
					{
						created: Math.ceil(Date.now() / 1000),
						updated: Math.ceil(Date.now() / 1000),
						status: Math.random() > 0.5 ? 0 : 1,
						name: '@cname',
						phone: /1(3|5|7|8|9)[0-9][0-9]{8}/,
						wx: '@string',
						passWord: '@string'
					},
					config.body
				)
			)
		}
	},
	{
		url: 'apimember/save',
		type: 'post',
		response: config => {
			return responseData(
				Object.assign(
					{
						created: Math.ceil(Date.now() / 1000),
						updated: Math.ceil(Date.now() / 1000)
					},
					config.body
				)
			)
		}
	},

	{
		url: 'apirole/grouplist',
		type: 'post',
		response: config => {
			const body = config.body
			const limit = body.limit || 10
			const pageTotal = parseInt(Math.random() * 10) || 1
			let dataOptions = {
				page_index: body.p,
				page_limit: limit,
				page_total: pageTotal,
				row_total: pageTotal * limit
			}
			dataOptions['items|' + limit] = [
				{
					'id|+1': 1 + (body.p - 1) * limit,
					created: Math.ceil(Date.now() / 1000),
					updated: Math.ceil(Date.now() / 1000),
					status: () => ('status' in body ? body.status : Math.random() > 0.5 ? 0 : 1),
					title: '@ctitle',
					remarks: '@csentence',
					rules: 'admin'
				}
			]
			return responseData(dataOptions)
		}
	},
	{
		url: 'apirole/groupdetail',
		type: 'post',
		response: config => {
			return responseData(
				Object.assign(
					{
						created: Math.ceil(Date.now() / 1000),
						updated: Math.ceil(Date.now() / 1000),
						status: Math.random() > 0.5 ? 0 : 1,
						title: '@ctitle',
						remarks: '@csentence',
						roles:
							'1,10020,10023,10061,10024,10059,10114,10021,10056,10022,10047,10033,10190,10193,10192,10191,10194,10195,10016,10017,10093,10084,10018,10081,10019,10086,10169,10171,10170,10196,10207,10206,10205,10204,10203,10202,10201,10200,10199,10198,10197,10135,10143,10185,10136,10137,10139,10140,10145,10141,10138,10147,10151,10150,10149,10144,10148,10142,10146,10062,10087,10077,10076,10063,10074,10066,10072,10071,10070,10065,10068,10078,10064,10080,10085,10083,10082,10184,10183,10181,10167,10168,2,10101,10108,10107,10106,10105,10104,10103,10102,10109,10053,10055,10054,10058,10057,10060,10034,10046,10048,10041,10049,10050,10052,10051,10039,10045,10044,10035,10036,10037,10038,10040,10042,10043,10095,10097,10096,10098,10099,10100,10088,10094,10091,10090,10092,10009,10015,10110,10111,10112,10113,10014'
					},
					config.body
				)
			)
		}
	},
	{
		url: 'apirole/groupsave',
		type: 'post',
		response: config => {
			return responseData(
				Object.assign(
					{
						created: Math.ceil(Date.now() / 1000),
						updated: Math.ceil(Date.now() / 1000)
					},
					config.body
				)
			)
		}
	},
	{
		url: 'apirole/rolelist',
		type: 'post',
		response: config => {
			return responseData({ data: roleData })
		}
	},
	{
		url: 'apirole/roledetail',
		type: 'post',
		response: config => {
			return responseData(
				Object.assign(
					{
						name: 'admin/apimember/',
						title: '@ctitle',
						pid: 2,
						parentdefaultProps: [1, 10001],
						is_menu: Math.random() > 0.5 ? 0 : 1,
						status: Math.random() > 0.5 ? 0 : 1
					},
					config.body
				)
			)
		}
	},
	{
		url: 'apirole/rolesave',
		type: 'post',
		response: config => {
			return responseData(
				Object.assign(
					{
						created: Math.ceil(Date.now() / 1000),
						updated: Math.ceil(Date.now() / 1000)
					},
					config.body
				)
			)
		}
	},
	{
		url: 'apifile/upload',
		type: 'post',
		response: config => {
			console.log(config.body)
			return responseData({})
		}
	}
]
